package com.zmx.common.common.config;

import com.zmx.common.common.utils.id.Id;
import com.zmx.common.common.utils.id.Id0ddEven;
import com.zmx.common.common.utils.id.SnowflakeIdWorker;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: zookeeper配置
 * @ClassName: ZookeeperConfig
 * @Author zhaomxr
 * @Date 2021-10-12 16:45
 */
@Data
@Configuration
@ConfigurationProperties("zookeeper.id")
public class ZookeeperConfig {

    private String zkAddress;

    private int port;

    private String leafName;

    @Bean("id")
    public Id snowflakeId() {
        return new SnowflakeIdWorker(zkAddress, port, leafName, 1577836800000L);
    }

    @Bean("id0ddEven")
    public Id0ddEven snowflakeId0ddEven() {
        return new SnowflakeIdWorker(zkAddress, port, leafName, 1577836800000L);
    }
}
